//Copyright 2008 Marcos Boyington
//Simple class that globs up all translation from ResX -> .resources and source file
using System;
using System.Collections.Generic;
using System.Text;
using System.Web.Compilation;
using System.Web.Hosting;
using System.Resources;
using System.CodeDom;

namespace ResXImproved
{
	public abstract class ResXBuildProviderBase : BuildProvider
	{
		public abstract bool GenerateInternal
		{
			get;
		}
		public override void GenerateCode(AssemblyBuilder assemblyBuilder)
		{
			string name = System.IO.Path.GetFileNameWithoutExtension(base.VirtualPath);
			ResourceWriter writer = new ResourceWriter(assemblyBuilder.CreateEmbeddedResource(this, String.Format("resources.{0}.resources", name)));

			ResXGenerator gen = new ResXGenerator(assemblyBuilder, name);
			gen.GenerateInternal = GenerateInternal;
			CodeCompileUnit compileUnit;
			gen.GenerateResources(VirtualPathProvider.OpenFile(base.VirtualPath), writer, out compileUnit);
			assemblyBuilder.AddCodeCompileUnit(this, compileUnit);

			writer.Close();
		}
	}

	public sealed class ResXBuildProvider : ResXBuildProviderBase
	{
		public override bool GenerateInternal
		{
			get { return false; }
		}
	}

	public sealed class ResXBuildProviderInternal : ResXBuildProviderBase
	{
		public override bool GenerateInternal
		{
			get { return true; }
		}
	}
}
